//package com.zookeeper.mine.study.config;
//
//import com.zookeeper.mine.study.utils.TestUtils;
//import org.apache.zookeeper.WatchedEvent;
//import org.apache.zookeeper.Watcher;
//import org.apache.zookeeper.Watcher.Event.*;
//import org.apache.zookeeper.ZooKeeper;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.annotation.Order;
//
//import java.util.concurrent.CountDownLatch;
//
//@Configuration
//@Order(value = 1)
//public class ZKBean {
//
//    @Value("${zookeeper.connect.infos}")
//    private String connectString;
//    @Value("${zookeeper.session.timeout}")
//    private Integer sessionTimeout;
//
//    private CountDownLatch latch = new CountDownLatch(1);
//
//    @Bean
//    public TestUtils test() {
//        return new TestUtils();
//    }
//
//
//    @Bean
//    public ZooKeeper zooKeeper() throws Exception {
//
//        ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, new Watcher() {
//            @Override
//            public void process(WatchedEvent watchedEvent) {
//                System.out.println("监听器，监听到的事件时：" + watchedEvent);
//                if (KeeperState.SyncConnected == watchedEvent.getState()) {
//                    System.out.println("建立连接");
//                    latch.countDown();
//                }
//            }
//        });
//
//        latch.await();
//
//        return zooKeeper;
//    }
//
//}
